//城市选择
var app = getApp();
Page({
  data: {
    code:0,
    openid: '',
  },
  formSubmit: function (e) {
    var adds = e.detail.value;
    // var open_id = app.globalData.userInfo['openid'];
    
    console.log(this.data.openid+'----openid');
    if(adds.name != '' && adds.suihao != ''){
      wx.request({
        url: app.api.kzdsurl + '/FeijiUser/add_invoice',
        data: {
          openid: this.data.openid,
          title: adds.name,
          number: adds.suihao
        },
        method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        header: {// 设置请求的 header
          'Content-Type':  'application/x-www-form-urlencoded'
        },
        success: function (res) {
          // success
          console.log(res)
          var status = res.data.status;
          if(status==1){
            wx.showToast({
              title: '保存成功！',
              duration: 2000
            });
          }else{
            // wx.showToast({
            //   title: res.data.err,
            //   icon: 'fail',
            //   duration: 2000
            // });
          }
          setTimeout(function(){
            wx.redirectTo({
              url: '../ticketchoose/index'
            });
          },3000)
        },
        fail: function () {
          // fail
          wx.showToast({
            title: '网络异常！',
            icon: 'fail',
            duration: 2000
          });
        }
      })
    }else if(adds.name == ''){
      wx.showToast({
        title: '请填写发票抬头',
        icon: 'none',
        duration: 2000
      });
    }else if(adds.suihao == ''){
      wx.showToast({
        title: '请填写发票税号',
        icon: 'none',
        duration: 2000
      });
    }


  },
  onShow: function () {
    var that = this;
    wx.getStorage({
      key: 'openid',
      success(res) {
        that.setData({
          openid: res.data
        })
      }
    })
  },
  onLoad: function (options) {
    // 生命周期函数--监听页面加载
    var that = this;
    

  },

})